﻿using System;
using System.Collections.Generic;
using Lenic.DI.Lifetimes;

namespace Lenic.DI
{
    /// <summary>
    /// DI 容器接口
    /// </summary>
    public interface IContainer : IEnumerable<ILifetime>, IDisposable
    {
        /// <summary>
        /// 在容器解析 ILifetime 对象失败后触发
        /// </summary>
        event Register OnResolveError;

        /// <summary>
        /// 向容器中注册组件
        /// </summary>
        /// <typeparam name="TService">委托返回值类型</typeparam>
        /// <param name="component">待注册的组件实例对象</param>
        /// <returns>修改后的自身</returns>
        IContainer Register<TService>(Registration<TService> component);

        /// <summary>
        /// 解析的具体实现
        /// </summary>
        /// <param name="serviceType">待解析的类型</param>
        /// <param name="name">解析类型的命名名称</param>
        /// <param name="lifetime">解析的实例对象.</param>
        /// <returns><c>true</c> 表示成功获取; 否则返回 <c>false</c> .</returns>
        bool TryResolve(Type serviceType, string name, out ILifetime lifetime);

        /// <summary>
        /// 解析的具体实现。
        /// </summary>
        /// <param name="serviceType">待解析的类型</param>
        /// <param name="lifetimes">解析的实例对象数组。</param>
        /// <returns><c>true</c> 表示成功获取; 否则返回 <c>false</c> 。</returns>
        bool TryResolve(Type serviceType, out ILifetime[] lifetimes);

        /// <summary>
        /// 获取当前对象关联的扩展属性集合。
        /// </summary>
        /// <value>
        /// 当前对象关联的扩展属性集合。
        /// </value>
        IDictionary<string, object> Tag { get; }
    }
}